import { createApp } from 'vue'
import App from './App.vue'
import router from './router'

import 'font-awesome/css/font-awesome.min.css'
import axios from 'axios'
import qs from 'qs'
import {
    getCurDate,
    getLocalStorage,
    setLocalStorage,
    getSessionStorage,
    setSessionStorage,
    removeLocalStorage,
    removeSessionStorage
} from './common.js'

//设置axios的基础url
axios.defaults.baseURL = 'http://62.234.13.26:8082'
// axios.defaults.baseURL = '/pro'
// axios.defaults.baseURL = '/dev'

//挂载axios到app中
const app = createApp(App);
app.config.globalProperties.$axios = axios;
app.config.globalProperties.$qs = qs;
app.config.globalProperties.$getCurDate = getCurDate;
app.config.globalProperties.$getLocalStorage = getLocalStorage;
app.config.globalProperties.$getSessionStorage = getSessionStorage;
app.config.globalProperties.$setSessionStorage = setSessionStorage;
app.config.globalProperties.$setLocalStorage = setLocalStorage;
app.config.globalProperties.$sessionStorage = sessionStorage;
app.config.globalProperties.$removeLocalStorage = removeLocalStorage;
app.config.globalProperties.$removeSessionStorage = removeSessionStorage;

router.beforeEach(function (to, from, next) {
    let user = sessionStorage.getItem('user')
    //除了登录,注册，首页，商家列表，商家信息之外都需要判断是否登录
    if (!(to.path == '/' || to.path == '/index' || to.path == '/businessList' || to.path == '/businessInfo' ||
        to.path == '/login' || to.path == '/register' || to.path == '/discover')) {
        if (user == null) {
            router.push('/login');
            // location.reload();
        }
    }
    next();
})

app.use(router).mount('#app')
